<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="/struts-tags" prefix="s"%>
<script type="text/javascript" charset="utf-8" src="js/jquery.listnav.min-2.1.js"></script>
<script type="text/javascript" charset="utf-8" src="js/jquery.dataTables.listnav.js"></script>
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
		var oTable = $('#service-table').dataTable({
			"sDom" : 'Zfrtp',
			"sPaginationType" : "bootstrap",
			"iDisplayLength" : 4,
			"bServerSide" : true,
			"bPaginate" : true,
			"sAjaxSource" : "serviceTableAjax.action",
		 	"oListNav": {
		        iIndex: 1,
		        sIdList: "lnList",
		        sWrapperClass : null
		    },
			"aoSearchCols": [
				null,
				null,
				null,
				null,
				null,
				{"sSearch": "Yes"}
			],
			"aoColumnDefs" : [{
				"fnRender" : function(o, val) {
					if (o.aData[5] == "Yes") {
						return '<a href=editService.action?serviceId=' + o.aData[6] + '>' + o.aData[1] + '</a>';
					} else {
						return '<a href="#" onClick=toActiveService(' 
								+ o.aData[0]
								+ ')>' 
								+ o.aData[1] 
								+ '</a>';
					}
				},
				"aTargets" : [1],
			}],
		});
		
		$('#check-active').click(function() {
			var other = $('#check-active:checked').val();
			if (other != undefined) {
				oTable.fnFilter("", 4, true, false);
			} else {
				oTable.fnFilter("Yes", 4, true, false);
			}
		});
	});
	
	function toActiveService(serviceId) {
		var r = confirm('Do you want to make this Service active?');
		if (r == true) {
			window.location.replace("activeService.action?serviceId=" + serviceId);
		}
	}
	
	function getURLParameter(name) {
	    return decodeURI(
	        (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
	    );
	}
	
</script>
<style type="text/css">
.dataTables_filter {
	display: none;
}

.dataTables_paginate {
	display: inline;
}
</style>

<s:if test="#session.logged != 'true'">
	<jsp:forward page="../index.jsp" />
</s:if>
<div class="container-fluid">
	<div class="content">
		<div class="row-fluid">
			<div class="span12">
				<div class="box">
					<div class="box-head">
						<h3>Service List</h3>
					</div>
					<div id="organisation" class="box-content">
						<div class="control-group">
							<div id="inactive-div">
								<a href="copyService.action" class="btn btn-success">Copy</a> 
								<a href="createService.action" class="btn btn-success">Create</a> 
								<label class="checkbox">
									<input type="checkbox" name="check-inactive" id="check-active"> Include In-active
								</label>
							</div>
							<table id="service-table" class="table table-striped table-bordered">
								<thead>
									<tr>
										<th></th>
										<th>Service Name</th>
										<th>Description</th>
										<th>Service Type</th>
										<th>Contact</th>
										<th>Is Active?</th>
									</tr>
								</thead>
								<tbody>
								</tbody>
							</table>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>